using System;
using System.Reflection;

namespace MMXSaveGameConverter
{
    internal static class ObjectExm
    {
        public static TField GetPrivateFieldValue<TField>(this object self, string fieldName)
        {
            if (self == null)
                throw new NullReferenceException();

            return (TField)self.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance).GetValue(self);
        }

        public static void SetPrivateFieldValue<TField>(this object self, string fieldName, TField value)
        {
            if (self == null)
                throw new NullReferenceException();

            self.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance).SetValue(self, value);
        }
    }
}